<%@page pageEncoding="utf-8" contentType="text/html; charset=utf-8"%>
<%@taglib prefix="s" uri="strutsTags"%>
<%@taglib prefix="ty" uri="/wyzzTags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<html>
	<base href="<%=basePath%>">
	<head>
		<s:head />
		<link href="<s:url value="/resource/css/style.css"/>" rel="stylesheet"
			type="text/css" />
		<jsp:include flush="true" page="/sitemesh/jsPackage.jsp"></jsp:include>
		<script type='text/javascript'
			src='dwr/interface/LeavebalanceCurrentYear.js'></script>
		<script type="text/javascript" src="dwr/interface/LeaveBalanceDWR.js"></script>
		<title>员工休假管理</title>
	</head>
	<body onload="hrm.common.check_order();">
		<jsp:include flush="true" page="div_updateBalance.jsp"></jsp:include>
		<br />
		<s:component template="bodyhead">
		</s:component>
		<form id="actionSrc" name="actionSrc"
			action="examin/leavebalanceCurYear.action" method="POST">
			<!--隐藏信息-->
			<s:hidden id="order" name="page.order" />
			<s:hidden id="operate" name="page.operate" />
			<s:hidden id="page.currentPage" name="page.currentPage" />
			<s:hidden id="updateIDs" name="updateIDs" value="" />
			<s:hidden id="lbType" name="lbType"
				value="%{leaveBalance.lbLeaveType}" />
			<s:hidden id="specialIds" name="specialIds" />
			<table width="100%" class="formtable">
				<tr>
					<td align="right">
						员工:
					</td>
					<td>
						<s:textfield id="lbs_Bean.emp"
							name="leaveBalance.lbEmpNo.empNoName" size="16" maxlength="64"></s:textfield>
					</td>

					<td align="right">
						查询条件:
					</td>
					<td>
						<s:select name="searchType" list="#{'1':'已设置假期','0':'未配置假期'}"></s:select>
					</td>
					<td align="right">
						地区:
					</td>
					<td>
						<s:select id="location"
							name="leaveBalance.lbEmpNo.empLocationNo.id" list="locationList"
							listKey="id" listValue="locationName" emptyOption="true"></s:select>
					</td>
					<td align="right">
						休假状态:
					</td>
					<td>
						<s:select id="lbs_Bean.status" name="leaveBalance.lbStatus"
							list="#{0:'请选择',1:'初始化',2:'允许请假',9:'禁止请假'}"></s:select>
					</td>
					<td colspan="2" rowspan="2" align="center">
						<input title="[Alt+F]" accesskey="F" name="submit_search"
							id="submit_search" class="button" type="submit" value="查询">
						<input title="[Alt+A]" accesskey="A" name="submit_all"
							id="submit_all" class="button" type="button"
							onclick="window.location='leavebalanceCurYear.action';"
							value="重置">
					</td>
				</tr>
				<tr>
					<td align="right">
						组织单元:
					</td>
					<td>
						<s:orgselector id="orgselector1"
							name="leaveBalance.lbEmpNo.empDeptNo.departmentName"
							hiddenFieldName="leaveBalance.lbEmpNo.empDeptNo.id" />
					</td>
					<td align="right">
						休假类型:
					</td>
					<td>
						<s:select id="leaveBalance.lbLeaveType"
							name="leaveBalance.lbLeaveType"
							onchange="document.getElementById('actionSrc').submit()"
							list="#{1:'年假',5:'带薪病假'}" emptyOption="false"></s:select>
					</td>
					<td align="right">
						按天/小时:
					</td>
					<td>
						<s:select id="leaveType" name="leaveType" list="#{0:'按天',1:'按小时'}"
							onchange="document.getElementById('order').value='';document.getElementById('actionSrc').submit();"></s:select>
					</td>
				</tr>
			</table>

			<!-- 操作 -->
			<div class="operatediv">
				<input type="hidden" name="searchOrExport" id="searchOrExport" />
				<span class="operatedivleft"> <input class="button"
						type="button" id="down" name="down" value="上一年"
						onclick="previewYear();"> <s:textfield id="year"
						name="leaveBalance.lbYear" size="7"
						onkeyup="value=value.replace(/\D/g,'')"></s:textfield> <input
						class="button" type="button" id="up" name="up" value="下一年"
						onclick="nextYear();"> <input id="initSelect"
						name="initSelect" class="button" type="button" value="假期初始化"
						onclick="empSelector_searchEmp();hrm.common.openDialog('dlgVacationInitial');">
					<input id="submitLeaveBalance" name="submitLeaveBalance"
						class="button" type="button" value="提交"
						onclick="doSubmitLeaveBalnace();"> <input
						id="deleteLeaveBalance" name="deleteLeaveBalance" class="button"
						type="button" value="删除" onclick="doDeleteLeaveBalance()">
					<input class="button" type="button"
						onclick="initDivImmUpload('ILeaveBalance', '<s:property value="leaveBalance.lbYear"/>');"
						value="数据导入" /> <s:if test="leaveBalance.lbLeaveType == 1">
						<input class="button" type="button" value="年假余额表导出"
							onclick="doExport('export')" />
					</s:if> <s:else>
						<input class="button" type="button" value="带薪病假余额表导出"
							onclick="doExport('export')" />
					</s:else> </span>
				<span class="operatedivright">本次查询共得到<s:property
						value="page.totalRows" />条休假记录</span>
			</div>

			<table cellpadding="0" cellspacing="0" width="100%" border="0"
				class="gridtableList">
				<tr>
					<th>
						<input id="changIds" name='changIds' class="checkbox"
							type="checkbox"
							onclick="hrm.common.checkAllByName('changIds','changIds');"
							value="选中草稿">
					</th>
					<th>
						<a href="#"
							onclick="hrm.common.order_submit('emp.empDistinctNo','actionSrc');">员工编号</a>
						<img src='resource/images/arrow_.gif' width='8' height='10'
							id='emp.empDistinctNo_img'>
					</th>
					<th>
						<a href="#"
							onclick="hrm.common.order_submit('emp.empName','actionSrc');">员工姓名</a>
						<img src='resource/images/arrow_.gif' width='8' height='10'
							id='emp.empName_img'>
					</th>
					<th>
						<a href="#"
							onclick="hrm.common.order_submit('lbLeaveType','actionSrc');">种类</a>
						<img src='resource/images/arrow_.gif' width='8' height='10'
							id='lbLeaveType_img'>
					</th>
					<s:if
						test="leaveBalance.lbLeaveType == 1 || leaveBalance.lbLeaveType == 10">
						<th>
							<s:if test="leaveType==0">
								<a href="#"
									onclick="hrm.common.order_submit('lbBalForwardDay','actionSrc');">上年余额(天)</a>
								<img src='resource/images/arrow_.gif' width='8' height='10'
									id='lbBalForwardDay_img'>
							</s:if>
							<s:else>
								<a href="#"
									onclick="hrm.common.order_submit('lbBalForwardHour','actionSrc');">上年余额(小时)</a>
								<img src='resource/images/arrow_.gif' width='8' height='10'
									id='lbBalForwardHour_img'>
							</s:else>
						</th>
						<th>
							<a href="#"
								onclick="hrm.common.order_submit('lbBalEndDate','actionSrc');">余额到期日</a>
							<img src='resource/images/arrow_.gif' width='8' height='10'
								id='lbBalEndDate_img'>
						</th>
					</s:if>
					<th>
						<s:if test="leaveType==0">
							<a href="#"
								onclick="hrm.common.order_submit('lbDaysOfYear','actionSrc');">本年额度(天)</a>
							<img src='resource/images/arrow_.gif' width='8' height='10'
								id='lbDaysOfYear_img'>
						</s:if>
						<s:else>
							<a href="#"
								onclick="hrm.common.order_submit('lbHoursOfYear','actionSrc');">本年额度(小时)</a>
							<img src='resource/images/arrow_.gif' width='8' height='10'
								id='lbHoursOfYear_img'>
						</s:else>
					</th>
					<s:if
						test="leaveBalance.lbLeaveType == 1 || leaveBalance.lbLeaveType == 5">
						<th>
							<s:if test="leaveType==0">
								<a href="#"
									onclick="hrm.common.order_submit('lbDaysForRelease','actionSrc');">释放额度(天)</a>
								<img src='resource/images/arrow_.gif' width='8' height='10'
									id='lbDaysForRelease_img'>
							</s:if>
							<s:else>
								<a href="#"
									onclick="hrm.common.order_submit('lbHoursForRelease','actionSrc');">释放额度(小时)</a>
								<img src='resource/images/arrow_.gif' width='8' height='10'
									id='lbHoursForRelease_img'>
							</s:else>
						</th>
						<th>
							<a href="#"
								onclick="hrm.common.order_submit('lbReleaseStartDate','actionSrc');">释放起始日</a>
							<img src='resource/images/arrow_.gif' width='8' height='10'
								id='lbReleaseStartDate_img'>
						</th>
					</s:if>
					<s:if test="leaveBalance.lbLeaveType == 1">
						<th>
							<a href="#"
								onclick="hrm.common.order_submit('lbOtherDays','actionSrc');">法定(天)</a>
							<img src='resource/images/arrow_.gif' width='8' height='10'
								id='lbOtherDays_img'>
						</th>
					</s:if>
					<th>
						<a href="#"
							onclick="hrm.common.order_submit('lbComments','actionSrc');">备注</a>
						<img src='resource/images/arrow_.gif' width='8' height='10'
							id='lbComments_img'>
					</th>
					<th>
						<a href="#"
							onclick="hrm.common.order_submit('lbStatus','actionSrc');">状态</a>
						<img src='resource/images/arrow_.gif' width='8' height='10'
							id='lbStatus_img'>
					</th>
					<th>
						操作
					</th>
				</tr>
				<s:if test="result!=null&&!result.isEmpty()">
					<s:iterator value="result" status="index">
						<tr id="row_<s:property value='leaveBalance.lbId'/>">
							<td align="center">
								<s:if test="leaveBalance!=null">
									<input type="hidden" id="empName<s:property value='id'/>"
										value="<s:property value='empName'/>" />
									<input id="changIds" type="checkbox" name="changIds"
										class="checkbox"
										value="<s:property value='leaveBalance.lbId'/>" onclick="" />
								</s:if>
							</td>
							<td align="center">
								<a href="#" class="listViewTdLinkS1"
									onclick="showEmpLtInfo('<s:property value='id'/>');"><s:property
										value="empDistinctNo" /> </a>
							</td>
							<td>
								<s:property value='empName' />
							</td>
							<td>
								<s:if test="leaveBalance != null">
									<s:if test="leaveBalance.lbLeaveType == 1">年假</s:if>
									<s:elseif test="leaveBalance.lbLeaveType == 5">带薪病假</s:elseif>
								</s:if>
							</td>
							<s:if
								test="leaveBalance.lbLeaveType == 1 || leaveBalance.lbLeaveType == 10">
								<td>
									<s:if test="leaveType==0">
										<s:property value="leaveBalance.lbBalForwardDay" />
									</s:if>
									<s:else>
										<s:property value="leaveBalance.lbBalForwardHour" />
									</s:else>
								</td>
								<td>
									<s:date name="leaveBalance.lbBalEndDate" format="yyyy-MM-dd" />
								</td>
							</s:if>
							<td>
								<s:if test="leaveType==0">
									<s:property value="leaveBalance.lbDaysOfYear" />
								</s:if>
								<s:else>
									<s:property value="leaveBalance.lbHoursOfYear" />
								</s:else>
							</td>
							<s:if
								test="leaveBalance.lbLeaveType == 1 || leaveBalance.lbLeaveType == 5">
								<td>
									<s:if test="leaveType==0">
										<s:property value="leaveBalance.lbDaysForRelease" />
									</s:if>
									<s:else>
										<s:property value="leaveBalance.lbHoursForRelease" />
									</s:else>
								</td>
								<td>
									<s:date name="leaveBalance.lbReleaseStartDate"
										format="yyyy-MM-dd" />
								</td>
							</s:if>
							<s:if test="leaveBalance.lbLeaveType == 1">
								<td>
									<s:property value="leaveBalance.lbOtherDays" />
								</td>
							</s:if>
							<td>
								<s:property value="leaveBalance.lbComments" />
							</td>
							<td nowrap="nowrap">
								<s:if test="leaveBalance.lbStatus==1">初始化</s:if>
								<s:elseif test="leaveBalance.lbStatus==2">允许请假</s:elseif>
								<s:elseif test="leaveBalance.lbStatus==9">禁止请假</s:elseif>
							</td>
							<td nowrap="nowrap">
								<s:if test="leaveBalance!=null">
									<!--以下两个方法在Div_updateBalance.jsp中-->
									<img
										onclick="showUpdateBalanceDiv('<s:property value='leaveBalance.lbId'/>')"
										alt='调整' title='调整' class="urlimg"
										src="resource/images/edit.gif" />
									<img
										onclick="deleteBalance('<s:property value='leaveBalance.lbId'/>')"
										alt='清除' title='清除' class="urlimg"
										src="resource/images/delete.gif" />
								</s:if>
							</td>
						</tr>
					</s:iterator>
				</s:if>
				<s:else>
					<tr>
						<td align="center" colspan="11">
							<s:if test="leaveBalance != null">
								<s:if test="leaveBalance.lbLeaveType == 1">不存在符合条件的年假信息！</s:if>
								<s:elseif test="leaveBalance.lbLeaveType ==5">不存在符合条件的带薪病假信息！</s:elseif>
								<s:elseif test="leaveBalance.lbLeaveType ==10">不存在符合条件的调休假信息！</s:elseif>
							</s:if>
						</td>
					</tr>
				</s:else>
			</table>
			<s:pager end="page.end" pageNo="page.currentPage"
				totalRows="page.totalRows" totalPages="page.totalPages"
				formId="actionSrc" start="page.start" />
		</form>

		<!-- 选择员工弹出层  点击页面假期初始化按钮弹出Dialog-->
		<div id="dlgVacationInitial" title="员工假期初始化" class="prompt_div_inline">
			<s:empselector id="empselector1" name="emp.empDeptNo.departmentName"
				condition="leaveBalance&year" hiddenFieldName="emp.empDeptNo.id" />
			<table width="100%">
				<tr>
					<td>
						休假类型:&nbsp;
						<input type="checkbox" class="checkbox" id="annual" />
						年假&nbsp;
						<input type="checkbox" class="checkbox" id="sick" />
						带薪病假&nbsp;
					</td>
				</tr>
				<tr>
					<td align="center">
						<input id="btnInit" class="button" type="button" value="确定"
							onclick="doInit();">
						<input id="btnClose" class="button" type="button" value="取消"
							onclick="hrm.common.closeDialog('dlgVacationInitial');" />
					</td>
				</tr>
			</table>
		</div>

		<!-- 请假种类汇总弹出层 -->
		<div id="dlgEmpLtInfo" class="prompt_div_inline" style="width: 560px;">
			<table id="listTable" width="100%" class="gridview">
				<thead>
					<th>
						开始时间
					</th>
					<th>
						结束时间
					</th>
					<th>
						合计时间
					</th>
					<th>
						请假理由
					</th>
				</thead>
				<tbody id="listBody">

				</tbody>
				<tr>
					<td align="center">
						本年已用额度合计
					</td>
					<td id="valueRow1" align="center" colspan="3"></td>
				</tr>
				<tr>
					<td align="center">
						本年可用余额
					</td>
					<td id="valueRow2" align="center" colspan="3"></td>
				</tr>
				<tr>
					<td colspan="4" class="prompt_div_bottom">
						<input id="empLrClose" class="button" type="button" value="关闭"
							onclick="hrm.common.closeDialog('dlgEmpLtInfo');" />
					</td>
				</tr>
			</table>
		</div>
	</body>

	<script type="text/javascript">
model.simple.setParentIFrameFull("IFrame1"); // add by w（计算iframe高度） 
	
//给initSelect赋初始值(假期初始化可见性)
function setInitStatus(var1){
	try{
	     //alert('1setInitStatus');
	    checkBoxName=document.getElementsByName(var1);  //$N(var1);
	                
	    if(checkBoxName.length>1)
		{
			for(var i=1;i<checkBoxName.length;i=i+1)
			{
				if(checkBoxName[i].checked==true){
				$("#initSelect").attr("disabled",false);  //$('#initSelect').disabled=false;
				return;
				}
			}
		}
		}catch(e){
			alert(e);
		}
		$("#initSelect").attr("disabled",true);
}

//下一年记录(点击页面下一年按钮)
function nextYear(){
	submitForm(1);
}

//上一年记录
function previewYear(){
	submitForm(-1);
}

//提交表单(可调用公共方法)
function submitForm(year){
	var date = document.getElementById("year").value;
	document.getElementById("year").value = parseInt(date)+year;
	document.actionSrc.submit();
}

//onkeydown按下键盘触发
function enterDown(event){
    event = event ? event : (window.event ? window.event : null);
    if(event!=null && event.keyCode==13){
        searchEmp(document.getElementById('emp_sear_value').value);  
        return;                              
    }
}
    
//初始化Dialog(点击初始化按钮)    
function doInit(){
	var ids = empSelector_choseEmpIdStr();
    var len = ids.length;
    if(len ==0){
    	alert("请至少选择一个员工！");
        return;
    }
    var types = "";
    if(document.getElementById('annual').checked){
 		types += "1,"
    }
    if(document.getElementById('sick').checked){
   		types += "5,"
    }
    if(types.length ==0){
    	alert("请至少选择一个休假类型！");
        return;
    }
    var year = document.getElementById('year').value;
    if(!confirm("确定要初始化"+year+"年的休假吗?")){
   		return;
    }
    //document.getElementById('dlgVacationInitial').style.display='none';
    hrm.common.openDialog('dlgVacationInitial');
  	document.getElementById("actionSrc").action='examin/initLeaveBalance.action';
  	document.getElementById("updateIDs").value=ids;
  	document.getElementById("specialIds").value = types.substring(0,types.length-1);
  	document.getElementById("actionSrc").submit();
}

//获取选中的员工(以钩的)
function getCheckBoxIds(){
	var result = "";
	var ids = document.getElementsByName("changIds");
	for(var i = 0; i < ids.length; i++){
		if(ids[i].checked){
			var value = ids[i].value;
			if(value == null || value.length == 0){
				continue;
			}
			result += value + ",";
		}
	}
	return result == ""?"":result.substring(0,result.length-1);
}

//提交(点击提交按钮)   
function doSubmitLeaveBalnace(){
	var ids = getCheckBoxIds();
	if(ids.length ==0){
		alert("请选择要提交的记录!");
		return;
	}
	if(!confirm('确定要进行提交操作吗？')){
		return;
    }
	document.getElementById("actionSrc").action='examin/doSubmitLeaveBalance.action';
    document.getElementById("updateIDs").value=ids;
    //document.getElementById("specialIds").value = types.substring(0,types.length-1);
    document.getElementById("actionSrc").submit();
}

//删除(点击删除按钮) 
function doDeleteLeaveBalance(){
    var ids = getCheckBoxIds();
	if(ids.length ==0){
		alert("请选择要删除的记录!");
		return;
	}
	if(!confirm('确定要进行删除操作吗？')){
		return;
    }
	document.getElementById("actionSrc").action='doDeleteLeaveBalance.action';
    document.getElementById("updateIDs").value=ids;
    //document.getElementById("specialIds").value = types.substring(0,types.length-1);
    document.getElementById("actionSrc").submit();
}
        
// 显示员工请假详细信息； prototype-->jquery实现
function showEmpLtInfo(empId){
    // 清除上次显示的行；
    DWRUtil.removeAllRows("listBody");
    
    var ltSpecialCat = document.getElementById("leaveBalance.lbLeaveType").value;
    var year = document.getElementById("year").value;
    var dayOrHour = document.getElementById("leaveType").value;
    LeavebalanceCurrentYear.getEmpLtInfo(year, empId, ltSpecialCat, dayOrHour, showInfoCallback);
    // 回调函数；
    function showInfoCallback(data){
        if(data.length > 1){// 有请假数据，显示在列表中；
            for(var i=0; i<data.length-1; i++){
                var lr = data[i];
                var lrStartDate, lrEndDate, totalTime, lrReason;
                if(lr.lrStartApm!=null && lr.lrEndApm!=null){// 按天显示；
                	lrStartDate = lr.lrStartDate.toHRMDateString("yyyy-MM-dd") + " " + getAM_PMDesc(lr.lrStartApm);
            	    lrEndDate = lr.lrEndDate.toHRMDateString("yyyy-MM-dd") + " " + getAM_PMDesc(lr.lrEndApm); //format-->toHRMDateString(common.js中)
                }else{// 按小时显示；
                	lrStartDate = lr.lrStartDate.toFormatString("yyyy-MM-dd hh:mm");
                	lrEndDate = lr.lrEndDate.toFormatString("yyyy-MM-dd hh:mm"); //format-->toFormatString
                }
                if(dayOrHour==0){
                    totalTime = lr.lrTotalDays+"天";
                }else{
                    totalTime = lr.lrTotalHours+"小时";
                }
                lrStatus = lr.lrStatusMean;
                lrReason = lr.lrReason;

                // 添加行；
                var row = document.createElement("tr");
        		var cellFuncs = [
        		    function(item) { return lrStartDate; },
        		    function(item) { return lrEndDate; },
        		    function(item) { return totalTime; },
        		    function(item) { return lrReason; }
        		];
                DWRUtil.addRows("listBody", [''], cellFuncs, {
    			  rowCreator:function(options) {
    				var row = document.createElement("tr"); 
    				row.align="center";
    				return row;
    			    }
    		    });
            }
        }

        // 显示汇总值行；
		var valuesArr = data[data.length-1];
        var typeStr = dayOrHour==0?"天":"小时";
        // 已用数据行；
		document.getElementById("valueRow1").innerHTML = valuesArr[0]+typeStr;
		// 可用数据行；
		document.getElementById("valueRow2").innerHTML = valuesArr[1]+typeStr;

		// 设置标题；
		var currentEmpName = document.getElementById("empName"+empId).value;
		var catStr = "年假";
        if(ltSpecialCat == 5) catStr = "带薪病假";
        if(ltSpecialCat == 10) catStr = "调休假(不过期)";
        var title = currentEmpName+"的"+catStr+"汇总信息";
		
        $("#dlgEmpLtInfo").dialog("option", "title", title);
        hrm.common.openDialog('dlgEmpLtInfo');
    }
}

  
//上下午判断
function getAM_PMDesc(AM_PM){
    if(AM_PM==null || AM_PM==0){ 
        return "上午";
    }
    return "下午";
}

function doExport(exportName){
	document.getElementById('searchOrExport').value=exportName;
   	document.getElementById('actionSrc').submit();

   	document.getElementById('searchOrExport').value='';
}

hrm.common.initDialog('dlgVacationInitial',560);
hrm.common.initDialog('dlgEmpLtInfo');
</script>
	<jsp:include flush="true" page="../io/div_upload.jsp"></jsp:include>
</html>